<%@ page import="org.gnomus.server.Context" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%
  Context ctx = Context.get();
  Map user = ctx.account;
  List<Map> games = (List<Map>) ctx.data.get("games");
%>
<h2 class="d-inline">Games</h2>
<span class="f-right">
<%
  if (user == null) {
%>
  <a href="/user/sign_in?b=<%= ctx.uri %>">Sign in</a> to create one.
<%
  } else if (user != null && ctx.data.size() > 0) {
%>
  Feel free to <a href="/game/create">create</a> another.
<%
  }
%>
</span>
<hr />
<div id="sample_games" class="f-left">
  <h3>Samples</h3>
  <p>
    <a href="/game/play?sample=ps">Periodic Squares</a>
  </p>
  <p>
    <a href="/game/play?sample=be">Balancing Equations</a>
  </p>
</div>
<div id="user_games" class="f-right">
  <h3>User-created</h3>
  <%
    if (games == null || games.size() == 0) {
  %>
  <p>
    No user-created games found.
  </p>
  <%
      if (user != null) {
  %>
  <p>
    But you can <a href="/game/create">create</a> one.
  </p>
  <%
      }
  %>
  <%
    } else {
  %>
    <%
      for (Map game : games) {
    %>
  <p>
    <span>
      <a href="/game/view?id=<%= game.get("id") %>">
        <%= game.get("name") + " (" + game.get("type") + ")" %>
      </a>
    </span>
    <span class="small">
      created by <%= game.get("creator") %>
    </span>
  </p>
  <%
      }
    %>
  <%
    }
  %>
</div>